import rcu
def getRF():
    a = [0] * 15
    x = rcu.GetBluetoothData()&0x1f#只传递0,1,2,3,4过来，0是9号键值。    
    x1 = rcu.GetRFModuleRemoteCode(1)
    x=x | x1 | (x&1<<9)
    for i in range(1, 11):
        a[i] = (x >> i) & 1
    a[0] = x
    return a
fireTime=False
fireAngle=200
angles=[200,250]
fireSpeed=[100,80,60]
fSIndex=0
rcu.SetMagneticServoDegreeTime(3,fireAngle,500)
rcu.SetMagneticServoDegreeTime(2,220,200)
while True:
    a=getRF()
    if a[9]:
        rcu.SetWaitForTime(0.2)
        a=getRF()
        if a[9]:
            if not fireTime: 
               fireTime=True
               rcu.SetMagneticServoDegreeTime(2,220,0)
               rcu.SetMotor(1,fireSpeed[fSIndex])
               rcu.SetMotor(2,fireSpeed[fSIndex])
            else:
               fireTime=fireTime
               rcu.SetMotor(1,0)
               rcu.SetMotor(2,0)
               rcu.SetMagneticServoDegreeTime(2,220,0)
    if a[1]:
        fireAngle+=1
        if fireAngle>=angles[1]:fireAngle=angles[1]
        rcu.SetMagneticServoDegreeTime(3,fireAngle,0)
        rcu.SetWaitForTime(0.02)
    elif a[3]:
        fireAngle-=1
        if fireAngle<=angles[0]:fireAngle=angles[0]
        rcu.SetMagneticServoDegreeTime(3,fireAngle,0)
        rcu.SetWaitForTime(0.02)
    if a[6]:
        rcu.SetMotor(3,100)
        rcu.SetMotor(4,100)
    elif a[8]:
        rcu.SetMotor(3,-100)
        rcu.SetMotor(4,-100)
    else:
        rcu.SetMotor(3,0)
        rcu.SetMotor(4,0)
    if fireTime:        
        if a[2]:
            rcu.SetMagneticServoDegreeTime(2,80,500)
            rcu.SetWaitForTime(0.6)
            rcu.SetMagneticServoDegreeTime(2,220,200)
            rcu.SetWaitForTime(0.3)
        if a[4]:
           fSIndex+=1
           if fSIndex>=len(fireSpeed):fSIndex=0       
    else:
        if a[2]:
            rcu.SetMotor(3,100)
            rcu.SetMotor(4,100)
        elif a[4]:
            rcu.SetMotor(3,-100)
            rcu.SetMotor(4,-100)
        else:
            rcu.SetMotor(3,0)
            rcu.SetMotor(4,0)
        
    if a[10] and a[9]:
        for i in range(4):rcu.SetMotor(i+1,0)
        fireTime=False
        if not overTime:
            overTime=True
            rcu.SetDisplayString(1,"凯旋",0x001F,0xF800)
            rcu.SetDisplayString(2,"而归",0x001F,0xF800)
        else:
            overTime=False
            rcu.SetLCDClear(0)
        rcu.SetWaitForTime(0.5)#这个时间调整到一个合适的值